package org.neogenesis.web.controller;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.neogenesis.web.dao.ExperimentDAO;
import org.neogenesis.web.datamodel.LazyExperimentDataModel;
import org.neogenesis.web.model.Experiment;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;

@Named
@SessionScoped
public class ListGeoSeriesController implements Serializable {

	private List<Experiment> experiments;

	private LazyDataModel<Experiment> lazyModel;

	private Experiment selected;

	@Inject
	private ExperimentDAO experimentDAO;

	public ListGeoSeriesController() {
		
	}
	
	@PostConstruct
	private void init(){
		experiments = experimentDAO.findAll();
		lazyModel = new LazyExperimentDataModel(experiments);
	}

	public Experiment getSelected() {
		return selected;
	}

	public void setSelected(Experiment selected) {
		this.selected = selected;
	}

	public LazyDataModel<Experiment> getLazyModel() {
		return lazyModel;
	}

	public void setLazyModel(LazyDataModel<Experiment> lazyModel) {
		this.lazyModel = lazyModel;
	}
	
	public void onRowSelect(SelectEvent event) {		
		selected = (Experiment) event.getObject();
		
		FacesMessage msg = new FacesMessage("Experiment Selected",
				selected.getSeriesIid());
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

}
